﻿<!DOCTYPE html>
<html>
<head>
<%
    include("/static/include/title.html"){}
    include("/static/include/css.html"){}
    include("/static/include/js.html"){}
%>
</head>

<body>
<div class="layui-fluid">
	<form id="fExp" class="layui-form" action="../common/fileExport.do" onsubmit="return false" method="post">
		<input type="hidden" id="dialogId" name="dialogId" value="${parameter.dialogId}"/>
		<input type="hidden" name="key" value="${has(KEY_EXPORTER)?KEY_EXPORTER:''}"/>
		
		<%if(!has(file)) {%>
		<div class="layui-card">
			<div class="layui-card-header">
				<div class="layui-row">
					<div class="layui-col-xs6">选择导出字段</div>
					<div class="layui-col-xs6" style="text-align:right;"><input type="checkbox" lay-skin="primary" lay-filter="checkAll" checked name="all" title="全选"/></div>
				</div>
			</div>

			<div class="layui-card-body" style="padding: 15px;">
				<div class="layui-row">
				<%if(!isEmpty(exporter.titles)){ for(i in exporter.titles) {%>
				    <div class="layui-col-xs3">
				      <input type="checkbox" name="fieldNames" title="${i}" value="${exporter.fields[iLP.index - 1]}" lay-skin="primary" checked/>
				    </div>
				 <%}}%>
				  </div>
			</div>
		</div>
		
		<div class="layui-form-item layui-layout-admin">
			<div class="layui-input-block">
				<div class="layui-footer" style="left: 0;">
					<button class="layui-btn" onclick="doExport();">导 出</button>
				</div>
			</div>
		</div>
		<%} else {%>
		<div class="layui-card">
			<div class="layui-card-header">点击按钮下载</div>

			<div class="layui-card-body" style="padding: 15px;">
				<div class="layui-row">
				    <div class="layui-col-xs12">
				      <a href="../common/download?file=${file[0]}&name=${file[1]}" class="layui-btn" target="_blank">下载</a>
				    </div>
				</div>
			</div>
		</div>
		<%}%>
	</form>
</div>
<script>
	layui.use(['form'], function(){
        var form  = layui.form;
        var laydate = layui.laydate;
        
        form.on('checkbox(checkAll)', function(data) {
        	var checked = data.elem.checked; //是否被选中，true或者false

    		$("input:checkbox[name='fieldNames']").each(function() {
    			this.checked = checked;
    		});
    		
    		form.render("checkbox");
        });

        // 渲染表单radio、select、checkbox
        form.render();
    });

	function doExport() {
		// 注意：
		// 如果更改页面表单的控件类型，请在校验判断时做对应修改：
		// 1. 下拉框：使用 $.trim(theForm["控件名称"].value) == ""
		// 2. 单选框/复选框：使用 getChoiceValue("控件名称") == null
		// 	
		var fs = getChoiceValue("fieldNames");
		if(fs == null) {
			$.message("请选择需要导出的字段");
			return false;
		}
	
		document.forms[0].submit();
	}
</script>
</body>
</html>
